package com.example.tao_city.text1;

import android.os.Bundle;
import android.os.Handler;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import java.util.concurrent.RunnableFuture;

/**
 * Created by TAO_CITY on 2018/1/16.
 */

public class Chaxun_dukaqi extends Fragment implements View.OnClickListener{
    private View mv;
    private RelativeLayout layout;
    private boolean tuichu=true;
    private boolean start=false;
    private Handler handler;
    private int a=0;
    private int i=0;
    private RelativeLayout bianan;
    private ImageView jindu1,jindu2,jindu3,jindu4,jindu5,jindu6,jindu7,jindu8,jindu9;

    @Override
    public View onCreateView(LayoutInflater inflater,ViewGroup container,Bundle savedInstanceState) {
        mv=inflater.inflate(R.layout.chaxun_dukaqi,container,false);
        initbutton();
        return mv;
    }

    private void initbutton(){
        layout=mv.findViewById(R.id.dukaqi_quanbu);
        bianan=mv.findViewById(R.id.dukaqi_bianan);

        jindu1=mv.findViewById(R.id.dukaqi_jindu1);
        jindu2=mv.findViewById(R.id.dukaqi_jindu2);
        jindu3=mv.findViewById(R.id.dukaqi_jindu3);
        jindu4=mv.findViewById(R.id.dukaqi_jindu4);
        jindu5=mv.findViewById(R.id.dukaqi_jindu5);
        jindu6=mv.findViewById(R.id.dukaqi_jindu6);
        jindu7=mv.findViewById(R.id.dukaqi_jindu7);
        jindu8=mv.findViewById(R.id.dukaqi_jindu8);
        jindu9=mv.findViewById(R.id.dukaqi_jindu9);
        layout.setOnClickListener(this);

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.dukaqi_quanbu:
                if(i==0) {
                    WindowManager.LayoutParams lp =getActivity().getWindow().getAttributes();
                    lp.alpha = 0.6f;
                    getActivity().getWindow().setAttributes(lp);
                    getActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
                    //bianan.setVisibility(View.VISIBLE);
                    Fm1_Chaxun.an = true;
                    start = true;
                    i=1;
                }else {
                   // bianan.setVisibility(View.INVISIBLE);
                    Fm1_Chaxun.an=true;
                    start=false;
                    setbianan();
                    a=0;
                    i=0;
                }
               break;
        }
    }

    @Override
    public void onPause() {
        super.onPause();
        tuichu=false;
    }

    @Override
    public void onResume() {
        super.onResume();
        tuichu=true;
        start=false;
        handler=new Handler();
        handler.postDelayed(runnable,1);
    }

    Runnable runnable=new Runnable() {
        @Override
        public void run() {
            if(tuichu) {
                if (start) {
                    setbianan();
                    setliang(a);
                    a++;
                    if (a == 10) {
                        a = 0;
                    }
                }
              handler.postDelayed(this,500);
            }
        }
    };
    private void setbianan(){
        jindu1.setVisibility(View.INVISIBLE);
        jindu2.setVisibility(View.INVISIBLE);
        jindu3.setVisibility(View.INVISIBLE);
        jindu4.setVisibility(View.INVISIBLE);
        jindu5.setVisibility(View.INVISIBLE);
        jindu6.setVisibility(View.INVISIBLE);
        jindu7.setVisibility(View.INVISIBLE);
        jindu8.setVisibility(View.INVISIBLE);
        jindu9.setVisibility(View.INVISIBLE);
    }
    private void setliang(int i){
        switch (i){
            case 1:
                jindu1.setVisibility(View.VISIBLE);
                break;
            case 2:
                jindu1.setVisibility(View.VISIBLE);
                jindu2.setVisibility(View.VISIBLE);
                break;
            case 3:
                jindu1.setVisibility(View.VISIBLE);
                jindu2.setVisibility(View.VISIBLE);
                jindu3.setVisibility(View.VISIBLE);
                break;
            case 4:
                jindu1.setVisibility(View.VISIBLE);
                jindu2.setVisibility(View.VISIBLE);
                jindu3.setVisibility(View.VISIBLE);
                jindu4.setVisibility(View.VISIBLE);
                break;
            case 5:
                jindu1.setVisibility(View.VISIBLE);
                jindu2.setVisibility(View.VISIBLE);
                jindu3.setVisibility(View.VISIBLE);
                jindu4.setVisibility(View.VISIBLE);
                jindu5.setVisibility(View.VISIBLE);
                break;
            case 6:
                jindu1.setVisibility(View.VISIBLE);
                jindu2.setVisibility(View.VISIBLE);
                jindu3.setVisibility(View.VISIBLE);
                jindu4.setVisibility(View.VISIBLE);
                jindu5.setVisibility(View.VISIBLE);
                jindu6.setVisibility(View.VISIBLE);
                break;
            case 7:
                jindu1.setVisibility(View.VISIBLE);
                jindu2.setVisibility(View.VISIBLE);
                jindu3.setVisibility(View.VISIBLE);
                jindu4.setVisibility(View.VISIBLE);
                jindu5.setVisibility(View.VISIBLE);
                jindu6.setVisibility(View.VISIBLE);
                jindu7.setVisibility(View.VISIBLE);
                break;
            case 8:
                jindu1.setVisibility(View.VISIBLE);
                jindu2.setVisibility(View.VISIBLE);
                jindu3.setVisibility(View.VISIBLE);
                jindu4.setVisibility(View.VISIBLE);
                jindu5.setVisibility(View.VISIBLE);
                jindu6.setVisibility(View.VISIBLE);
                jindu7.setVisibility(View.VISIBLE);
                jindu8.setVisibility(View.VISIBLE);
                break;
            case 9:
                jindu1.setVisibility(View.VISIBLE);
                jindu2.setVisibility(View.VISIBLE);
                jindu3.setVisibility(View.VISIBLE);
                jindu4.setVisibility(View.VISIBLE);
                jindu5.setVisibility(View.VISIBLE);
                jindu6.setVisibility(View.VISIBLE);
                jindu7.setVisibility(View.VISIBLE);
                jindu8.setVisibility(View.VISIBLE);
                jindu9.setVisibility(View.VISIBLE);
                break;
        }
    }





}
